<template>
  <div class="ele-body">
    <el-card shadow="never">

      <!-- 搜索表单 -->
      <el-form :model="studentTable.where" label-width="77px" class="ele-form-search"
               @keyup.enter.native="$refs.classTable.reload()" @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :md="6" :sm="12">
            <el-form-item label="名单类型:">
              <el-input v-model="studentTable.where.person_type" placeholder="请输入名单类型" clearable/>
            </el-form-item>
          </el-col>
          <el-col :md="6" :sm="12">
            <el-form-item label="人员名称:">
              <el-input v-model="studentTable.where.name" placeholder="请输入人员名称" clearable/>
            </el-form-item>
          </el-col>
          <el-col :md="6" :sm="12">
            <el-form-item label="人脸活体检测:">
              <el-input v-model="studentTable.where.liveness" placeholder="请输入人脸活体检测" clearable/>
            </el-form-item>
          </el-col>
          <el-col :md="6" :sm="12">
            <div class="ele-form-actions">
              <el-button type="primary" @click="$refs.classTable.reload()" icon="el-icon-search" class="ele-btn-icon">查询
              </el-button>
              <el-button @click="(studentTable.where={})&&$refs.classTable.reload()">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>

      <!-- 操作按钮 -->
      <div class="ele-table-tool ele-table-tool-default">
        <el-button @click="showEdit=true" type="primary" icon="el-icon-plus" class="ele-btn-icon" size="small">添加
        </el-button>
        <el-button @click="remove()" type="danger" icon="el-icon-delete" class="ele-btn-icon" size="small">批量删除
        </el-button>
      </div>

      <!-- 数据表格 -->
      <ele-data-table ref="table" :config="studentTable" :choose.sync="choose" height="calc(100vh - 315px)" highlight-current-row>
        <template slot-scope="{index}">
          <el-table-column type="selection" width="45" align="center" fixed="left"/>
          <el-table-column type="index" :index="index" label="编号" width="60" align="center" fixed="left" show-overflow-tooltip/>
                  
          <el-table-column prop="device_id" label="来自设备DeviceId字段" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="device_uuid" label="设备唯一编号" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="person_type" label="名单类型" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="name" label="人员名称" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="numbers" label="工号" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="compare_result" label="比对结果，即相似度" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="capture_time" label="抓拍时间" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="send_time" label="抓拍上传的发送时间" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="face_id" label="人员id，若上传请求faceid不存在，则使用设备faceid" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="device_face_id" label="设备faceid" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="face_quality" label="图片质量" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="liveness" label="人脸活体检测" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="imgpath" label="上传的抓拍图片路径" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="imgexpath" label="人脸背景图路径" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="face_feature" label="" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="sub_device_ip" label="设备连接的子设备ip地址" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="temper" label="抓拍的人脸体温" sortable="custom" show-overflow-tooltip min-width="120"/>
                                
          <el-table-column prop="channel" label="NVR通道号" sortable="custom" show-overflow-tooltip min-width="120"/>
                  
          <el-table-column label="创建时间" sortable="custom" show-overflow-tooltip min-width="160">
            <template slot-scope="{row}">{{ row.create_time*1000 | toDateString }}</template>
          </el-table-column>
          <el-table-column label="更新时间" sortable="custom" show-overflow-tooltip min-width="160">
            <template slot-scope="{row}">{{ row.update_time*1000 | toDateString }}</template>
          </el-table-column>
          <el-table-column label="操作" width="130px" align="center" :resizable="false"  fixed="right">
            <template slot-scope="{row}">
              <el-link @click="edit(row)" icon="el-icon-edit" type="primary" :underline="false">修改</el-link>
              <el-popconfirm title="确定要删除此设备抓拍记录吗？" @confirm="remove(row)" class="ele-action">
                <el-link slot="reference" icon="el-icon-delete" type="danger" :underline="false">删除</el-link>
              </el-popconfirm>
            </template>
          </el-table-column>
        </template>
      </ele-data-table>
    </el-card>

    <!-- 编辑弹窗 -->
    <el-dialog :title="editForm.id?'修改设备抓拍记录':'修改设备抓拍记录'" :visible.sync="showEdit" width="450px"
               @closed="editForm={}" :destroy-on-close="true" :lock-scroll="false">
      <el-form :model="editForm" ref="editForm" :rules="editRules" label-width="100px">
                          
        <el-form-item label="来自设备DeviceId字段：" prop="device_id">
            <el-input v-model="editForm.device_id" placeholder="请输入来自设备DeviceId字段" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="设备唯一编号：" prop="device_uuid">
            <el-input v-model="editForm.device_uuid" placeholder="请输入设备唯一编号" clearable/>
        </el-form-item>
                                              
        <el-form-item label="名单类型：" prop="person_type">
          <el-select v-model="editForm.person_type" placeholder="请选择名单类型" class="ele-block" clearable>
            <el-option
                    v-for="item in []"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
                                                  
        <el-form-item label="人员名称：" prop="name">
            <el-input v-model="editForm.name" placeholder="请输入人员名称" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="工号：" prop="numbers">
            <el-input v-model="editForm.numbers" placeholder="请输入工号" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="比对结果，即相似度：" prop="compare_result">
            <el-input-number v-model="editForm.compare_result" controls-position="right" :min="0"
                              placeholder="请输入比对结果，即相似度" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="抓拍时间：" prop="capture_time">
            <el-input-number v-model="editForm.capture_time" controls-position="right" :min="0"
                              placeholder="请输入抓拍时间" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="抓拍上传的发送时间：" prop="send_time">
            <el-input-number v-model="editForm.send_time" controls-position="right" :min="0"
                              placeholder="请输入抓拍上传的发送时间" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="人员id，若上传请求faceid不存在，则使用设备faceid：" prop="face_id">
            <el-input-number v-model="editForm.face_id" controls-position="right" :min="0"
                              placeholder="请输入人员id，若上传请求faceid不存在，则使用设备faceid" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="设备faceid：" prop="device_face_id">
            <el-input-number v-model="editForm.device_face_id" controls-position="right" :min="0"
                              placeholder="请输入设备faceid" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="图片质量：" prop="face_quality">
            <el-input-number v-model="editForm.face_quality" controls-position="right" :min="0"
                              placeholder="请输入图片质量" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                  
        <el-form-item label="人脸活体检测：" prop="liveness">
          <el-select v-model="editForm.liveness" placeholder="请选择人脸活体检测" class="ele-block" clearable>
            <el-option
                    v-for="item in []"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
                                                  
        <el-form-item label="上传的抓拍图片路径：" prop="imgpath">
            <el-input v-model="editForm.imgpath" placeholder="请输入上传的抓拍图片路径" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="人脸背景图路径：" prop="imgexpath">
            <el-input v-model="editForm.imgexpath" placeholder="请输入人脸背景图路径" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="：" prop="face_feature">
            <el-input-number v-model="editForm.face_feature" controls-position="right" :min="0"
                              placeholder="请输入" class="ele-fluid ele-text-left"/>
        </el-form-item>
                                                      
        <el-form-item label="设备连接的子设备ip地址：" prop="sub_device_ip">
            <el-input v-model="editForm.sub_device_ip" placeholder="请输入设备连接的子设备ip地址" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="抓拍的人脸体温：" prop="temper">
            <el-input v-model="editForm.temper" placeholder="请输入抓拍的人脸体温" clearable/>
        </el-form-item>
                                                  
        <el-form-item label="NVR通道号：" prop="channel">
            <el-input-number v-model="editForm.channel" controls-position="right" :min="0"
                              placeholder="请输入NVR通道号" class="ele-fluid ele-text-left"/>
        </el-form-item>
                              
      </el-form>
      <div slot="footer">
        <el-button @click="showEdit=false">取消</el-button>
        <el-button type="primary" @click="save">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "SysCompare",
  data() {
    return {
      studentTable: {url: '/attendStudentRecord/index', where: {}},  // 表格配置
      choose: [],  // 表格选中数据
      showEdit: false,  // 是否显示表单弹窗
      editForm: {},  // 表单数据
      editRules: {  // 表单验证规则
                        
        device_id: [
          {required: true, message: '请输入来自设备DeviceId字段', trigger: 'blur'}
        ],
                                    
        device_uuid: [
          {required: true, message: '请输入设备唯一编号', trigger: 'blur'}
        ],
                          
        person_type: [
          {required: true, message: '请选择名单类型', trigger: 'blur'}
        ],
                                    
        name: [
          {required: true, message: '请输入人员名称', trigger: 'blur'}
        ],
                                    
        numbers: [
          {required: true, message: '请输入工号', trigger: 'blur'}
        ],
                          
        compare_result: [
          {required: true, message: '请输入比对结果，即相似度', trigger: 'blur'}
        ],
                          
        capture_time: [
          {required: true, message: '请输入抓拍时间', trigger: 'blur'}
        ],
                          
        send_time: [
          {required: true, message: '请输入抓拍上传的发送时间', trigger: 'blur'}
        ],
                          
        face_id: [
          {required: true, message: '请输入人员id，若上传请求faceid不存在，则使用设备faceid', trigger: 'blur'}
        ],
                          
        device_face_id: [
          {required: true, message: '请输入设备faceid', trigger: 'blur'}
        ],
                          
        face_quality: [
          {required: true, message: '请输入图片质量', trigger: 'blur'}
        ],
                          
        liveness: [
          {required: true, message: '请选择人脸活体检测', trigger: 'blur'}
        ],
                                    
        imgpath: [
          {required: true, message: '请输入上传的抓拍图片路径', trigger: 'blur'}
        ],
                                    
        imgexpath: [
          {required: true, message: '请输入人脸背景图路径', trigger: 'blur'}
        ],
                          
        face_feature: [
          {required: true, message: '请输入', trigger: 'blur'}
        ],
                                    
        sub_device_ip: [
          {required: true, message: '请输入设备连接的子设备ip地址', trigger: 'blur'}
        ],
                                    
        temper: [
          {required: true, message: '请输入抓拍的人脸体温', trigger: 'blur'}
        ],
                          
        channel: [
          {required: true, message: '请输入NVR通道号', trigger: 'blur'}
        ],
              
      },
    }
  },
  mounted() {
  },
  methods: {
    /**
     * 显示编辑
     */
    edit(row) {
      this.$http.get('/compare/info?id=' + row.id).then(res => {
        if (res.data.code === 200) {
          this.editForm = res.data.result.data;
          this.showEdit = true;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /**
     * 保存编辑
     */
    save() {
      this.$refs['editRuleForm'].validate((valid) => {
        if (valid) {
          const loading = this.$loading({lock: true});
          this.$http.post('/compare/edit', this.editForm).then(res => {
            loading.close();
            if (res.data.code === 200) {
              this.showEdit = false;
              this.$message({type: 'success', message: res.data.msg});
              this.$refs.classTable.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /**
     * 刪除(批量刪除)
     */
    remove(row) {
      console.log(row)
      if (!row) {  // 批量删除
        if (this.choose.length === 0) return this.$message.error('请至少选择一条数据');
        let ids = this.choose.map(d => d.id);
        this.$confirm('确定要删除选中的设备抓拍记录吗?', '提示', {type: 'warning'}).then(() => {
          const loading = this.$loading({lock: true});
          this.$http.post('/compare/delete', {id: ids}).then(res => {
            loading.close();
            if (res.data.code === 200) {
              this.$message({type: 'success', message: res.data.msg});
              this.$refs.classTable.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        }).catch(() => 0);
      } else {  // 单个删除
        const loading = this.$loading({lock: true});
        this.$http.post('/compare/delete', {id:row.id}).then(res => {
          loading.close();
          if (res.data.code === 200) {
            this.$message({type: 'success', message: res.data.msg});
            this.$refs.classTable.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }
    },
                                                                            }
}
</script>

<style scoped>
.ele-block >>> .el-upload, .ele-block >>> .el-upload-dragger {
  width: 100%;
}
</style>